package com.yx1996.bean.day03.tx.AccountService;

import com.yx1996.bean.day03.tx.AccountDao.AccountDaoImpl;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;

public class AccountServiceImpl implements AccountService {

    private AccountDaoImpl ad;
    private TransactionTemplate tt;


    @Override
    //转账方法
    public void account(Integer from,Integer to,Double money) {

        //开启事务(aop)
        //加钱
        ad.addMoney(to, money);

//        int i=1/0;

        //减钱
        ad.redMoney(from, money);

    }
  /*  @Override
    //转账方法
    public void account(final Integer from, final Integer to,final Double money) {


//开启事务(编码式)
        tt.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
                //加钱
                ad.addMoney(to, money);

                int i=1/0;
                //减钱
                ad.redMoney(from, money);
            }
        });
    }*/
    public void setAd(AccountDaoImpl ad) {
        this.ad = ad;
    }

    public void setTt(TransactionTemplate tt) {
        this.tt = tt;
    }
}
